package com.wac.data.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wac.data.service.DynamicService;
import com.wac.data.service.MessageService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author beta
 * @since 2023-03-16
 */
@RestController
@RequestMapping("/message")
public class MessageController {

	private static ObjectMapper objectMapper = new ObjectMapper();
	private Map<String, Object> messageList;

	@Resource
	private MessageService messageService;

	//0代表未读 1代表已读 -1代表全部
	@RequestMapping("/user")
	public String getUserMessage(int page, String id, int state) throws JsonProcessingException {
		return objectMapper.writeValueAsString(messageService.selectByUserId(page, id, state));
	}


	@RequestMapping("/read")
	public String getUserMessageHaveState(String id) {
		return "success" + "-已读-" + messageService.hasReadAll(id);
	}

}

